from rest_framework.generics import ListAPIView
from rest_framework.viewsets import ModelViewSet

from goods.models import SpecificationOption, SPUSpecification
from meiduo_admin.my_paginate import MyPageNumberPagination
from meiduo_admin.serializers import spu_specs_options_serializers

class SPUSpecsOptionsSpecView(ModelViewSet):
    pagination_class = MyPageNumberPagination
    serializer_class = spu_specs_options_serializers.SPUSpecsOptionsSpecSerializer
    queryset = SpecificationOption.objects.all()

class SPUSpecView(ListAPIView):
    serializer_class = spu_specs_options_serializers.SPUSpecSerializer
    # queryset = SPUSpecification.objects.all()

    def get_queryset(self):
        queryset = SPUSpecification.objects.all()
        for spu_spec in queryset:
            spu_spec.name = "%s-%s"%(spu_spec.spu.name,spu_spec.name)
        return queryset